package commonChars;

import java.util.*;

public class Solution {
    static char[] chars = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    public List<String> commonChars(String[] words) {
        // 统计每个字母在每个单词中出现的最小次数
        List<String> ans = new ArrayList<>();
        for (int i = 0; i < chars.length; i++) {
            int min = Integer.MAX_VALUE;
            for (String s: words) {
                int count = 0;
                for (char c: s.toCharArray()) {
                    if(c == chars[i]){
                        count++;
                    }
                }
                min = Math.min(min,count);
            }
            for (int j = 0; j < min; j++) {
                ans.add(chars[i]+"");
            }
        }
        return ans;
    }
}
